package co.fitstart.entity.courseware.fitnessgroup;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.courseware.movement.Movement;

/**
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "courseware_template")
@PersistentFormat
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class CoursewareTemplate {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 组数 */
    private int groupAmount;
    
    /** 每组动作次数 */
    private int movementNumber;
    
    /** 最大重量 */
    private String maxWeight;
    
    /** 计时 */
    private String time;
    
    /** 动作类别 */
    @Enumerated(EnumType.ORDINAL)
    private CoursewareMovementType type;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private Movement movement;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private DailyCoursewareTemplate daily;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private SpecialCoursewareTemplate special;
    
    /** 排序 */
    private Integer ranking;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public CoursewareTemplate() {
        
    }
    
    /**
     * 
     * @param courseware
     * @param daily
     */
    public CoursewareTemplate(CoursewareTemplate courseware, DailyCoursewareTemplate daily) {
        this.groupAmount = courseware.getGroupAmount();
        this.movementNumber = courseware.getMovementNumber();
        this.maxWeight = courseware.getMaxWeight();
        this.time = courseware.getTime();
        this.type = courseware.getType();
        this.movement = courseware.getMovement();
        this.daily = daily;
        this.ranking = courseware.getRanking();
        this.disabled = courseware.isDisabled();
    }
    
    /**
     * 
     * @param courseware
     * @param special
     */
    public CoursewareTemplate(CoursewareTemplate courseware, SpecialCoursewareTemplate special) {
        this.groupAmount = courseware.getGroupAmount();
        this.movementNumber = courseware.getMovementNumber();
        this.maxWeight = courseware.getMaxWeight();
        this.time = courseware.getTime();
        this.type = courseware.getType();
        this.movement = courseware.getMovement();
        this.special = special;
        this.ranking = courseware.getRanking();
        this.disabled = courseware.isDisabled();
    }
    
    public CoursewareTemplate(CoursewareTemplate template, DailyCoursewareTemplate daily, CoursewareMovementType type) {
        this.groupAmount = template.getGroupAmount();
        this.movementNumber = template.getMovementNumber();
        this.type = type;
        this.movement = template.getMovement();
        this.daily = daily;
        this.disabled = false;
    }
    
    /**
     * 
     * @param daily
     * @param type
     * @return
     */
    public CoursewareTemplate initilization(DailyCoursewareTemplate daily, CoursewareMovementType type) {
        this.daily = daily;
        this.type = type;
        this.disabled = false;
        return this;
    }
    
    /**
     * 
     * @param special
     * @param type
     * @return
     */
    public CoursewareTemplate initilization(SpecialCoursewareTemplate special) {
        this.special = special;
        this.disabled = false;
        return this;
    }
    

    /**
     * 
     * @param ranking
     * @return
     */
    public CoursewareTemplate editRanking(int ranking) {
        this.ranking = ranking;
        
        return this;
    }
    
    /**
     * 
     * @return
     */
    public CoursewareTemplate riseRanking() {
        this.ranking -= 1;
        
        return this;
    }
    
    /**
     * 
     * @return
     */
    public CoursewareTemplate dropRanking() {
        this.ranking += 1;
        
        return this;
    }
    
    /**
     * 
     * @return
     */
    public CoursewareTemplate disable() {
        this.disabled = true;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the groupAmount
     */
    public int getGroupAmount() {
        return groupAmount;
    }

    /**
     * @return the movementNumber
     */
    public int getMovementNumber() {
        return movementNumber;
    }

    /**
     * @return the maxWeight
     */
    public String getMaxWeight() {
        return maxWeight;
    }

    /**
     * @return the time
     */
    public String getTime() {
        return time;
    }

    /**
     * @return the type
     */
    public CoursewareMovementType getType() {
        return type;
    }

    /**
     * @return the movement
     */
    public Movement getMovement() {
        return movement;
    }

    /**
     * @return the daily
     */
    public DailyCoursewareTemplate getDaily() {
        return daily;
    }

    /**
     * @return the special
     */
    public SpecialCoursewareTemplate getSpecial() {
        return special;
    }

    /**
     * @return the ranking
     */
    public Integer getRanking() {
        return ranking;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param groupAmount the groupAmount to set
     */
    public void setGroupAmount(int groupAmount) {
        this.groupAmount = groupAmount;
    }

    /**
     * @param movementNumber the movementNumber to set
     */
    public void setMovementNumber(int movementNumber) {
        this.movementNumber = movementNumber;
    }

    /**
     * @param maxWeight the maxWeight to set
     */
    public void setMaxWeight(String maxWeight) {
        this.maxWeight = maxWeight;
    }

    /**
     * @param time the time to set
     */
    public void setTime(String time) {
        this.time = time;
    }

    /**
     * @param type the type to set
     */
    public void setType(CoursewareMovementType type) {
        this.type = type;
    }

    /**
     * @param movement the movement to set
     */
    public void setMovement(Movement movement) {
        this.movement = movement;
    }

    /**
     * @param daily the daily to set
     */
    public void setDaily(DailyCoursewareTemplate daily) {
        this.daily = daily;
    }

    /**
     * @param special the special to set
     */
    public void setSpecial(SpecialCoursewareTemplate special) {
        this.special = special;
    }

    /**
     * @param ranking the ranking to set
     */
    public void setRanking(Integer ranking) {
        this.ranking = ranking;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
